using System;
using Ext;
using ScriptFX;

namespace SampleScripts {
    public class SamplePanel : Panel {
        public new bool autoHeight = true;
        public new bool frame = true;
        public new bool collapsible = true;
        public new string cls = "demos";

        public static XTemplate tpl = new XTemplate(
                    "<dl>" +
                    "<tpl for=\"samples\">" +
                    "<dt><a href=\"{url}\" target=\"_blank\"><img src=\"shared/screens/{icon}\"/></a><br/>" +
                    "<span>{text}</span>" +
                    "</dt>" +
                    "</tpl>" +
                    "</dl><div style=\"clear:both\"></div>");

        public SamplePanel(object config) {
            Type.InvokeMethod(typeof (SamplePanel), "superclass.constructor.call", this, config);
        }

        public void afterRender() {
            Type.InvokeMethod(typeof(SamplePanel), "superclass.afterRender.call", this);
            tpl.overwrite(Type.GetField(this, "body"), this);
        }
    }

    public class DefaultScript {
        public static void main(Dictionary args) {
            ExtClass.onReady(new AnonymousDelegate(delegate() { new DefaultScript().init(); }));
        }

        public void init() {
            Dictionary[] catalog = new Dictionary[] {
                new Dictionary(
                    "title", "Grids",
                    "samples", new Dictionary[] {
                        new Dictionary(
                            "text", "Basic Array Grid",
                            "url", "grid/array-grid.aspx",
                            "icon", "grid-array.gif"
                        ),
                        new Dictionary(
                            "text", "Editable Grid",
                            "url", "grid/edit-grid.aspx",
                            "icon", "grid-edit.gif"
                        ),
                        new Dictionary(
                            "text", "XML Grid",
                            "url", "grid/xml-grid.aspx",
                            "icon", "grid-xml.gif"
                        ),
                        new Dictionary(
                            "text", "Paging",
                            "url", "grid/paging.aspx",
                            "icon", "grid-paging.gif"
                        ),
                        new Dictionary(
                            "text", "Grouping",
                            "url", "grid/grouping.aspx",
                            "icon", "grid-grouping.gif"
                        ),
                        new Dictionary(
                            "text", "Live Group Summary",
                            "url", "grid/totals.aspx",
                            "icon", "grid-summary.gif"
                        ),
                        new Dictionary(
                            "text", "Customizing: Grid Plugins",
                            "url", "grid/grid3.aspx",
                            "icon", "grid-plugins.gif"
                        )
                    }
                ), 
                new Dictionary(
                    "title", "Tabs",
                    "samples", new Dictionary[] {
                        new Dictionary(
                            "text", "Basic Tabs",
                            "url", "tabs/tabs.aspx",
                            "icon", "tabs.gif"
                        ),
                        new Dictionary(
                            "text", "Advanced Tabs",
                            "url", "tabs/tabs-adv.aspx",
                            "icon", "tabs-adv.gif"
                        )
                    }
                ), 
                new Dictionary(
                    "title", "Windows",
                    "samples", new Dictionary[] {
                        new Dictionary(
                            "text", "Hello World",
                            "url", "window/hello.aspx",
                            "icon", "window.gif"
                        ),
                        new Dictionary(
                            "text", "MessageBox",
                            "url", "message-box/msg-box.aspx",
                            "icon", "msg-box.gif"
                        )
                    }
                ), 
                new Dictionary(
                    "title", "Trees",
                    "samples", new Dictionary[] {
                        new Dictionary(
                            "text", "Drag and Drop Reordering",
                            "url", "tree/reorder.aspx",
                            "icon", "tree-reorder.gif"
                        ),
                        new Dictionary(
                            "text", "Multiple trees",
                            "url", "tree/two-trees.aspx",
                            "icon", "tree-two.gif"
                        ),
                        new Dictionary(
                            "text", "Customizing: Column Tree",
                            "url", "tree/column-tree.aspx",
                            "icon", "tree-columns.gif"
                        )
                    }
                ), 
                new Dictionary(
                    "title", "Layout Managers",
                    "samples", new Dictionary[] {
                        new Dictionary(
                            "text", "Border Layout",
                            "url", "layout/complex.aspx",
                            "icon", "border-layout.gif"
                        ),
                        new Dictionary(
                            "text", "Anchor Layout",
                            "url", "form/anchoring.aspx",
                            "icon", "anchor.gif"
                        ),
                        new Dictionary(
                            "text", "Customizing: Portals",
                            "url", "layout/portal.aspx",
                            "icon", "portal.gif"
                        )
                    }
                ), 
                new Dictionary(
                    "title", "ComboBox",
                    "samples", new Dictionary[] {
                        new Dictionary(
                            "text", "Basic ComboBox",
                            "url", "form/combos.aspx",
                            "icon", "combo.gif"
                        ),
                        new Dictionary(
                            "text", "Customizing: ComboBox Templates",
                            "url", "form/forum-search.aspx",
                            "icon", "combo-custom.gif"
                        )
                    }
                ), 
                new Dictionary(
                    "title", "Forms",
                    "samples", new Dictionary[] {
                        new Dictionary(
                            "text", "Dynamic Forms",
                            "url", "form/dynamic.aspx",
                            "icon", "form-dynamic.gif"
                        ),
                        new Dictionary(
                            "text", "Ajax with XML Forms",
                            "url", "form/xml-form.aspx",
                            "icon", "form-xml.gif"
                        ),
                        new Dictionary(
                            "text", "Customizing: Search Field",
                            "url", "form/custom.aspx",
                            "icon", "form-custom.gif"
                        )
                    }
                ), 
                new Dictionary(
                    "title", "Toolbars and Menus",
                    "samples", new Dictionary[] {
                        new Dictionary(
                            "text", "Basic Toolbar",
                            "url", "menu/menus.aspx",
                            "icon", "toolbar.gif"
                        ),
                        new Dictionary(
                            "text", "Ext Actions",
                            "url", "menu/actions.aspx",
                            "icon", "toolbar-actions.gif"
                        )
                    }
                ), 
                new Dictionary(
                    "title", "Miscellaneous",
                    "samples", new Dictionary[] {
                        new Dictionary(
                            "text", "DataView",
                            "url", "view/data-view.aspx",
                            "icon", "data-view.gif"
                        ),
                        new Dictionary(
                            "text", "Progress Bar",
                            "url", "simple-widgets/progress-bar.aspx",
                            "icon", "progress.gif"
                        ),
                        new Dictionary(
                            "text", "Templates",
                            "url", "core/templates.aspx",
                            "icon", "templates.gif"
                        ),
                        new Dictionary(
                            "text", "Panels",
                            "url", "panel/panels.aspx",
                            "icon", "panel.gif"
                        ),
                        new Dictionary(
                            "text", "Resizable",
                            "url", "resizable/basic.aspx",
                            "icon", "resizable.gif"
                        )
                    }
                ) 
            };

            for (int i = 0; i < catalog.Length; i++) {
                Dictionary c = catalog[i];
                c["id"] = "sample-" + i;
                new SamplePanel(c).render("all-demos");
            }

            XTemplate tpl = new XTemplate("<dl><tpl for=\".\"><dt><a href=\"#{id}\">{title:stripTags}</a></dt></tpl></dl>");
            tpl.overwrite("demo-menu", catalog);

            ExtClass.select("#sample-spacer").remove();
            ExtClass.get("loading").fadeOut(new Dictionary("remove", true));
        }
    }
}
